import subprocess

# 执行 ADB 命令的函数
def run_adb_command(command):
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = process.communicate()
    return output, error


# 在设备上保存屏幕截图
output, error = run_adb_command("adb shell screencap -p /sdcard/screenshot.png")
print("Output:", output)
print("Error:", error)

# 将屏幕截图从设备拉取到电脑
local_path = "screenshot.png" # 您可以更改这个路径
output, error = run_adb_command(f"adb pull /sdcard/screenshot.png {local_path}")
print("Output:", output)
print("Error:", error)